package com.crb.smartcard.utils;

import android.content.Context;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;

/**
 * Created by hank on 2017/4/20.
 */

public class NfcUtil {
    private NfcUtil() {
            /* cannot be instantiated */
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    /**
     * 判断是否有nfc功能
     *
     * @param context
     * @return
     */
    public static boolean hasNfc(Context context){
        boolean bRet=false;
        if(context==null){
            return bRet;
        }
        NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
        NfcAdapter adapter = manager.getDefaultAdapter();
        if (adapter != null) {
            // adapter存在，能启用
            bRet=true;
        }
        return bRet;
    }

    /**
     * 是否已开启nfc 功能
     * @param context
     * @return
     */
    public static boolean isEnableNfc(Context context){
        boolean bRet=false;
        if(context==null){
            return bRet;
        }
        NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
        if (manager!=null) {
            NfcAdapter adapter = manager.getDefaultAdapter();
            if (adapter != null && adapter.isEnabled()) {
                // adapter存在，能启用
                bRet=true;
            }
        }
        return bRet;
    }
}
